﻿using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using MyFloridaHouse.DataAccess.Extensions;
using MyFloridaHouse.libSvDTO;
using MyFloridaHouse.LibDTO;
using System.Data.SqlClient;

namespace MyFloridaHouse.DataAccess
{
    /// <summary>
    /// Data access layer storage operation methods for regions data
    /// </summary>
    public partial class DAL_CensusData
    {

        /// <summary>
        /// Gets the layer data dictionary.
        /// </summary>
        /// <returns></returns>
        public List<DataDictionaryDTO> GetLayerDataDictionary(int layerID)
        {
            List<DataDictionaryDTO> itemList = new List<DataDictionaryDTO>();

            SqlConnection db = Connect();
            SqlCommand cmd = new SqlCommand("	SELECT *  FROM " + DAL_Global.GetPrefixFromLayerID(layerID) + "Dictionary  ", db);
            db.Open();
            using (SqlDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    itemList.Add(DataDictionaryDTODataContract.DataContract(rdr));
                }
            }

            return itemList;
        }

        // The below method was the old way before moving DAL to DAL_Global
        //
        ///// <summary>
        ///// [Obsolete] Gets the layer data dictionary.
        ///// </summary>
        ///// <returns></returns>
        ///// <remarks>[Obsolete] SPROC: usp_GetConfigLayerDataDictionary</remarks>
        //public List<DataDictionaryDTO> GetLayerDataDictionary()
        //{
        //    List<DataDictionaryDTO> itemList = new List<DataDictionaryDTO>();

        //    //string storedProcedureName = "usp_GetConfigLayerDataDictionary";
        //    string storedProcedureName = "usp_tl10GetConfigLayerDataDictionary10";

        //    SqlConnection db = Connect();
        //    SqlCommand StoredProcedureCommand = new SqlCommand(storedProcedureName, db);
        //    StoredProcedureCommand.CommandType = CommandType.StoredProcedure;
        //    db.Open();
        //    using (SqlDataReader rdr = StoredProcedureCommand.ExecuteReader())
        //    {
        //        while (rdr.Read())
        //        {
        //            itemList.Add(DataDictionaryDTODataContract.DataContract(rdr));
        //        }
        //    }

        //    //Database db = Connect();
        //    ////DbCommand dbCommand = db.GetStoredProcCommand("usp_GetConfigLayerDataDictionary");
        //    //DbCommand dbCommand = db.GetStoredProcCommand("usp_tl10GetConfigLayerDataDictionary10");
        //    //dbCommand.CommandTimeout = 60000;
        //    //using (IDataReader rdr = db.ExecuteReader(dbCommand))
        //    //{
        //    //    while (rdr.Read())
        //    //    {
        //    //        itemList.Add(DataDictionaryDTODataContract.DataContract(rdr));
        //    //    }
        //    //}
        //    return itemList;
        //}
    }
}
